package com.yning.coroutines.demo.seven.kotlin

import com.yning.coroutines.Log

/**
 * 关于协程部分的序列生成器
  */

fun main() {
    seven_test_two()
}

fun seven_test_one(){
    val fibonacci = sequence {
        yield(1L) // first Fibonacci number
        var cur = 1L
        var next = 1L
        while (true) {
            yield(next) // next Fibonacci number
            val tmp = cur + next
            cur = next
            next = tmp
        }
    }
    fibonacci.take(5).forEach(){
        Log.d(it)
    }
}

fun seven_test_two(){
    val seq = sequence {
        Log.d("yield 1,2,3")
        yieldAll(listOf(1, 2, 3))
        Log.d("yield 4,5,6")
        yieldAll(listOf(4, 5, 6))
        Log.d("yield 7,8,9")
        yieldAll(listOf(7, 8, 9))
    }

    seq.take(5).forEach(){
        Log.d(it)
    }
}
